Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: Simplenote converter handles empty notes correctly #2793

Merged

Conversation

mmorella-dev
Copy link
Contributor

@mmorella-dev mmorella-dev commented Jan 24, 2024

Fixes standardnotes/forum#3462

The current implementation of SimplenoteConverter uses the following helper function to validate notes.json:

const isSimplenoteEntry = (entry: any): boolean => entry.id && entry.content && entry.creationDate && entry.lastModified

Because && is used here instead of a null check, this function returns false when content is an empty string "". This can trivially occur in notes where the user clicked "New Note" but did not enter any data. For example:

{
  "id": "e5ae4e85-a6a4-45d9-8994-6e693483f679",
  "content": "",
  "creationDate": "2024-01-02T01:37:22.615Z",
  "lastModified": "2024-01-02T01:38:26.662Z"
}

This PR rewrites the function to instead use Object.prototype.hasOwnProperty to query for the existence of each property, which produces the expected output when content is an empty string.

Copy link
Member

@amanharwara amanharwara left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thanks for the PR!

Looks like lint is failing (https://github.com/standardnotes/app/actions/runs/7636015424/job/20817657669?pr=2793#step:5:57) Please fix those issues.

Also, please run yarn test SimplenoteConverter in packages/ui-services and make sure that passes.

@mmorella-dev
Copy link
Contributor Author

@amanharwara Thanks for the heads up! I was hasty to get this out last night so I only tested it in a REPL. The new version should avoid those Lint errors. Tests pass on my machine.

It's valid for entry.content to be an empty string, so the truthiness check discards valid
	inputs where content is empty. Change this to a null check.

Fixes standardnotes/forum#3462
@mmorella-dev mmorella-dev force-pushed the fix-simplenote-null-check branch 2 times, most recently from 08bd073 to 96e4e27 Compare January 24, 2024 17:50
@amanharwara amanharwara self-requested a review January 24, 2024 18:09
Copy link
Member

@amanharwara amanharwara left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks again!

@amanharwara amanharwara merged commit cf0a7a6 into standardnotes:main Jan 24, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants